package cn.xugongwei.microserviceprovide8441.controller;

import cn.xugongwei.microservicecommon.entity.UserEntity;
import cn.xugongwei.microserviceprovide8441.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xugongwei (isxugongwei(a)gmail.com)
 * @version 1.0
 * @date 2019/4/10 12:10
 */
@RestController
@RequestMapping("/provide/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 要想被监控必须使用@HystrixCommand注解
     *
     * @return
     */
    @GetMapping("/list")
    @HystrixCommand
    public List<UserEntity> list() {
        return userService.listUser();
    }

    @GetMapping("/get/{id}")
    @HystrixCommand
    public UserEntity get(@PathVariable("id") Integer id) {
        return userService.getUserById(id);
    }
}
